package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"distributed/registry"
)

func main() {
	registry.SetupRegistryService()
	http.Handle("/services", &registry.RegistryService{})

	ctx, cancel := context.WithCancel(context.Background())
	// defer cancel()

	var svr http.Server
	svr.Addr = registry.ServerPort

	go func() {
		log.Println(svr.ListenAndServe())
		cancel()
	}()

	go func() {
		fmt.Println("registry service started. Press any to stop.")
		var input string
		fmt.Scanln(&input)
		svr.Shutdown(ctx)
		cancel()
	}()

	<-ctx.Done()
	fmt.Println("Shutting down registry service.")
}
